public class PlusOne {

    public int[] solution(int[] nums){

        for (int i = nums.length-1; i>0 ; i--) {
            if(nums[i]<9){
                nums[i]++;
                return nums;
            }else {
                nums[i]=0;
            }
        }
        int[] newNums=new int[nums.length+1];
        newNums[0]=1;
        return newNums;
    }
}
